package ejbssesions;

import javax.ejb.LocalBean;
import javax.ejb.Stateless;
import javax.persistence.Query;

import mundo.Motor;
import daos.Dao;

/**
 * Session Bean implementation class MotorDao
 */
@Stateless
@LocalBean
public class MotorDao extends Dao<Motor, Integer>{

	/**
	 * Obtiene la entidad
	 * @return La entidad
	 */
	protected Class<Motor> getEntityClass() {
		return Motor.class;
	}

	/**
	 * Obtiene el ultimo motor creado
	 * @return El ultimo motor creado
	 */
	public Motor getUltimoMotor(){
		Query query = entityManager.createQuery("select motor from Motor motor where motor.codigo = (select MAX(mot.codigo) from Motor mot)" );
		return (Motor)query.getSingleResult(); 
	}
	
}
